import { checkAuth } from "@/utils/auth";

export default {
  onShow() {
    const whiteList = ["pages/login/login", "pages/index/index"]; // 不需要登录的页面列表
    const currentPage = getCurrentPages().pop()?.route || "pages/index/index";

    if (!whiteList.includes(currentPage)) {
      checkAuth().then((isAuthenticated) => {
        if (!isAuthenticated) {
          console.log("跳转到登录页面进行登录。currentPage=", currentPage);
		  uni.navigateTo({
		    url: `/pages/login/login?redirect=${encodeURIComponent(currentPage)}`,
		  }).catch(err=>{
			  console.log("error------",err);
			  return false;
		  });
          return false;
        }
      });
    } else {
      console.log("mixin====currentPage=", currentPage);
    }
  },
};
